<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>小区列表</title>
    <link rel="stylesheet" th:href="@{/src/css/layui.css}">
</head>
<body>
<blockquote class="layui-elem-quote list_search">
        <div class="layui-inline">
            <a class="layui-btn layui-btn-normal roleAdd_btn"><i
                    class="layui-icon">&#xe608;</i> 添加小区</a>
        </div>
    <div class="layui-inline">
        <input type="text" id="plotName" class="layui-input plotName"
               name="plotName" placeholder="请输入小区名" value="">
    </div>
    <div class="layui-inline">
        <input type="text" id="plotPlace" class="layui-input plotPlace"
               name="plotPlace" placeholder="请输入小区地址" value="">
    </div>
    <div class="layui-inline">
        <input type="text" id="company" class="layui-input company"
               name="company" placeholder="请输入管辖物业" value="">
    </div>
    <a class="layui-btn search_btn" lay-submit="" data-type="search" lay-filter="search">查询</a>
    <div class="layui-inline">
        （支持模糊查询）
    </div>
</blockquote>
<table id="plorList" class="plorList" lay-filter="plorList"></table>
<script type="text/html" id="barEdit">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-xs" lay-event="user">业主</a>
</script>
<script th:src="@{/src/layui.js}"></script>
<script>
    layui.use(['jquery','layer','laypage','laytpl','table'],function () {
        var $ = layui.jquery,
            layer = layui.layer,
            laypage = layui.laypage,
            laytpl = layui.laytpl,
            table = layui.table;
        table.render({
            elem:'#plorList',
            url:'/plot/list',
            title:'小区列表',
            page:true,
            limit:10,
            limits:[10,20],
            cols:[
                [
                    {type:'checkbox'},
                    {title:'ID',field:'id',width:50},
                    {title:'小区名',field:'plotName'},
                    {title:'小区位置',field:'plotPlace'},
                    {title:'小区编号',field:'plotNum'},
                    {title:'创建时间',field:'createTime'},
                    {title:'更新时间',field:'updateTime'},
                    {title:'物业公司',field:'company'},
                    {title:'操作',templet:'#barEdit'}
                ]
            ],
            parseData:function(result){
                return {
                    code:result.code==200?0:result.code,
                    msg:result.message,
                    count:result.data.total,
                    data:result.data.list
                }
            }
        });
        //添加小区
        $(".roleAdd_btn").click(function () {
            layer.open({
                type:2,
                title:'添加小区',
                area:['400px','600px'],
                content:'/plot/addPlot'
            });
        });

        //动态查询
        $(".search_btn").click(function () {
            table.reload('plorList',{
                url:'/plot/list',
                page:1,
                where:{
                    company:$("#company").val(),//物业
                    plotPlace:$('#plotPlace').val(),//小区位置
                    plotName:$('#plotName').val()//小区名称
                },
                parseData:function (result) {
                    return {
                        count:result.data.total,
                        msg:result.message,
                        data:result.data.list,
                        code:result.code==200?0:result.code
                    }
                }
            })

        });
        //监听表格的行工具事件
        table.on('tool(plorList)',function (row) {
            var data = row.data;
            if(row.event === 'edit'){
                layer.open({
                    type:2,
                    title:'编辑小区',
                    area:['400px','600px'],
                    content:'/plot/editPlot?id='+data.id
                });

            }else if(row.event === 'user'){
                var index = layer.open({
                    type:2,
                    title:'业主列表',
                    content:'/plot/plotUser?plotId='+data.id
                });
                //窗口大小发生改变的时候触发该事件
                $(window).resize(function () {
                    layer.full(index);
                });
                layer.full(index);

            }else if(row.event === 'del'){
                layer.confirm("确定删除吗？",function (index) {
                    $.ajax({
                        url:'/plot/delete',
                        type:'delete',
                        data:{'id':data.id},
                        dataType:'json',
                        success:function (result) {
                            if (result.code == 200){
                                layer.msg(result.message,{icon:1},function () {
                                    location.reload();//删除成功刷新页面
                                });
                            } else {
                                layer.msg(result.message,{icon:5});
                            }
                        }
                    });
                    layer.close(index);
                });
            }
        })




    })
</script>

</body>
</html>